package leetcode.Y2024M6.study;

import leetcode.Y2024M6.TreeNode;
import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

public class S100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }

    @Test
    public void test() {
        int[] p = {1, 2, 3};
        int[] q = {1, 2, 3};
        TreeNode pTree = TreeNode.createTree(p);
        TreeNode qTree = TreeNode.createTree(q);
        System.out.println(isSameTree(pTree, qTree));

    }

    @Test
    public void test1() {
        int[] p = {1, 2, 1};
        int[] q = {1, 1, 2};
        TreeNode pTree = TreeNode.createTree(p);
        TreeNode qTree = TreeNode.createTree(q);
        System.out.println(isSameTree(pTree, qTree));

    }

    @Test
    public void test2() {
        int[] p = {1, 2};
        int[] q = {1, -1, 2};
        TreeNode pTree = TreeNode.createTree(p);
        TreeNode qTree = TreeNode.createTree(q);
        System.out.println(isSameTree(pTree, qTree));

    }

    @Test
    public void test3() {
        int[] p = {1, 2};
        int[] q = {1, -1, 2};
        TreeNode pTree = TreeNode.createTree(p);
        TreeNode qTree = TreeNode.createTree(q);
        System.out.println(isSameTree(pTree, qTree));

    }

    @Test
    public void test4() {
        int[] p = {1, -1, 2, 3};
        int[] q = {1, -1, 2, -1, 3};
        TreeNode pTree = TreeNode.createTree(p);
        TreeNode qTree = TreeNode.createTree(q);
        System.out.println(isSameTree(pTree, qTree));
    }


}
